//
//  SettingViewController.m
//  DebugDemo
//
//  Created by XFB on 2018/11/22.
//  Copyright © 2018年 ZhouCheng. All rights reserved.
//

#import "SettingViewController.h"
#import "MyProfileCell.h"
#import "MyProfileSectionModel.h"
#import "MyProfileItemModel.h"

@interface SettingViewController ()

@property (nonatomic, strong) NSArray *sectionArray;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupBasicSet];
    [self setupUI];
}

- (void)setupBasicSet
{
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"设置";
    [self.tableView registerClass:[MyProfileCell class] forCellReuseIdentifier:@"cell"];
    self.tableView.tableFooterView = [UIView new];
}

- (void)setupUI
{
    __weak typeof(self) weakSelf = self;
    
    MyProfileItemModel *item1 = [[MyProfileItemModel alloc] init];
    item1.themeName = @"反馈";
    item1.accessoryType = UserCenterAccessoryTypeIndicator;
    item1.ExecuteCode = ^{
        NSLog(@"反馈点击");
    };
    
    MyProfileItemModel *item2 = [[MyProfileItemModel alloc] init];
    item2.themeName = @"关于我们";
    item2.accessoryType = UserCenterAccessoryTypeIndicator;
    item2.ExecuteCode = ^{
        NSLog(@"关于我们点击");
    };
    
    MyProfileItemModel *item3 = [[MyProfileItemModel alloc] init];
    item3.themeName = @"消息通知";
    if ([[UIApplication sharedApplication] currentUserNotificationSettings].types == UIRemoteNotificationTypeNone) {
        item3.detailName = @"未开启";
    } else {
        item3.detailName = @"已开启";
    }
    item3.accessoryType = UserCenterAccessoryTypeIndicator;
    

    MyProfileItemModel *item4 = [[MyProfileItemModel alloc] init];
    item4.themeName = @"清除缓存";
    item4.accessoryType = UserCenterAccessoryTypeIndicator;
    CGFloat tempSize = [[SDImageCache sharedImageCache] getSize];
    tempSize = tempSize / (1024.0 * 1024.0);
    NSString *clearCacheName = tempSize >= 1 ? [NSString stringWithFormat:@"%.2fM",tempSize] : [NSString stringWithFormat:@"%.fKB", tempSize * 1024];
    item4.detailName = clearCacheName;
    /// 清除缓存
    item4.ExecuteCode = ^{
        NSLog(@"清除缓存操作");
    };
    
    
    MyProfileItemModel *item5 = [[MyProfileItemModel alloc] init];
    item5.themeName = @"发布投诉使用帮助";
    item5.accessoryType = UserCenterAccessoryTypeIndicator;
    
    MyProfileItemModel *item6 = [[MyProfileItemModel alloc] init];
    item6.themeName = @"用着不错给个好评";
    item6.accessoryType = UserCenterAccessoryTypeIndicator;

    MyProfileSectionModel *section1 = [[MyProfileSectionModel alloc] init];
    section1.itemArray = @[item1, item2, item3, item4, item5, item6];
    
    self.sectionArray = @[section1];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.sectionArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    MyProfileSectionModel *sectionModel = self.sectionArray[section];
    return sectionModel.itemArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MyProfileCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    MyProfileSectionModel *sectionModel = self.sectionArray[indexPath.section];
    MyProfileItemModel *itemModel = sectionModel.itemArray[indexPath.row];
    cell.itemModel = itemModel;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    MyProfileSectionModel *sectionModel = self.sectionArray[indexPath.section];
    MyProfileItemModel *itemModel = sectionModel.itemArray[indexPath.row];
    if (itemModel.ExecuteCode) {
        itemModel.ExecuteCode();
    }
}

@end
